
<script src="http://apps.bdimg.com/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript" src="../addons/{php echo $this->modulename}/res/js/jquery.form.js"></script>
<script  src="../addons/{php echo $this->modulename}/res/js/jquery.contextMenu.js" type="text/javascript"></script>
<script  src="../addons/{php echo $this->modulename}/res/js/designer.js" type="text/javascript"></script>
<link href="../addons/{php echo $this->modulename}/res/js/jquery.contextMenu.css" rel="stylesheet">
<link href="../addons/{php echo $this->modulename}/res/js/poster.css" rel="stylesheet">
<input type="hidden" name="reply_id" value="{$item['id']}" />
<input type="hidden" name="rtype" value="1" />
{php load()->func('tpl')}
<div class="main">
        <div class='panel panel-default'>
            <div class='panel-heading'>
                服务号海报设置
            </div>
            <div class='panel-body'>
               <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-1 control-label">海报类型</label>
                    <div class="col-xs-12 col-sm-9">
                      {if $_W['account']['level']==4}
                        <label class="radio-inline"><input type="radio" name="type" value="2" 
	         			 checked="checked">可以使用服务号海报</label>
                      {else}
                        <label class="radio-inline"><input type="radio" name="type" value="3"
                         checked="checked">您不可以使用服务号海报</label>
                      {/if}
                    </div>
                </div>
                {if $_W['account']['level']==4}
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-1 control-label">二维码类型</label>
                    <div class="col-xs-12 col-sm-9">
                        <label class="radio-inline"><input type="radio" name="qrtype" value="1" 
	         			{if $item['qrtype']==1} checked="checked" {/if}>临时二维码（有效期30天）</label>
                        <label class="radio-inline"><input type="radio" name="qrtype" value="0"
                        {if $item['qrtype']==0 || empty($item['qrtype'])} checked="checked"{/if}>永久二维码</label>
                    </div>
                </div>
                {else}
                <div class="form-group"  style="display:none">
                    <label class="col-xs-12 col-sm-3 col-md-1 control-label">二维码类型</label>
                    <div class="col-xs-12 col-sm-9">
                        <label class="radio-inline"><input type="radio" name="qrtype" value="1" 
	         			 checked="checked">临时二维码</label>
                    </div>
                </div>
                {/if}
                
                
                {if $_W['account']['level']<>4}
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-1 control-label">引导关注页</label>
                    <div class="col-sm-11 col-xs-12">
                        <input type="text" id="tzurl" name="tzurl" class="form-control" placeholder="【订阅号引导关注页面】需填写(扫描海报二维码，先跳转到这个页面引导关注)"  value="{$item['tzurl']}" />
                    </div>
                </div>
                 {/if}
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-1 control-label">海报名称</label>
                    <div class="col-sm-11 col-xs-12">
                        <input type="text" id="title" name="title" class="form-control"  value="{$item['title']}" />
                    </div>
                </div>
                
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-1 control-label">海报设计</label>
                    <div class="col-sm-11 col-xs-12">
                        <table style='width:100%;'>
                                <tr>
                                    <td id="bgtd" style='padding:10px;' valign='top'>
                                        <div id='nb_poster'>
                                          
                                          <img src="{if $item['bg']}{php echo toimage($item['bg'])}{else}{php echo '../addons/'.$this->modulename.'/res/images/posterbg.jpg'}{/if}" class='bg'/>
                                          
                                          {if !empty($data)}
                                          {loop $data $key $d}
                                          <div class="drag" type="{$d['type']}" index="{php echo $key+1}" style="zindex:{php echo $key+1};left:{$d['left']};top:{$d['top']};
                                               width:{$d['width']};height:{$d['height']}" size="{$d['size']}" color="{$d['color']}" > 
                                                {if $d['type']=='img' || $d['type']=='thumb'}
                                                  <img src="{php echo '../addons/'.$this->modulename.'/res/images/default.jpg'}" />
                                                {elseif $d['type']=='qr'}
                                                  <img src="../addons/{php echo $this->modulename}/res/images/qr.png" />
                                                {elseif $d['type']=='name'}
                                                   <div class=text style="font-size:{$d['size']};color:{$d['color']}" >昵称</div> 
                                                {/if}
                                              <div class="dRightDown"> </div><div class="dLeftDown"> </div><div class="dRightUp"> </div><div class="dLeftUp"> </div><div class="dRight"> </div><div class="dLeft"> </div><div class="rUp"> </div><div class="rDown"></div>
                                          </div>
                                          {/loop} 
                                          {/if}
                                        </div>
                                        
                                    </td>
                                    <td valign='top' style='padding:10px;'>
                                          <div class='panel panel-default'>
                                              <div class='panel-body'>
                                                    <div class="form-group">
                                                        <label class="col-xs-12 col-sm-3 col-md-2 control-label">海报元素</label>
                                                        <div class="col-sm-9 col-xs-12">
                                                        	<button class='btn btn-info btn-poster' type='button' data-type='img' >头像</button>
                                                             <button class='btn btn-primary btn-poster' type='button' data-type='name'>昵称</button>
                                                             <button class='btn btn-warning btn-poster' type='button' data-type='qr' >二维码</button>
                                                        </div>
                                                    </div>
                                                  <div id='namesset' style='display:none'>
                                                  <div class="form-group">
                                                        <label class="col-xs-12 col-sm-3 col-md-2 control-label">昵称颜色</label>
                                                         <div class="col-sm-9 col-xs-12">
                                                              {php echo tpl_form_field_color('color')}
                                                        </div>
                                                    </div>
                                                  <div class="form-group">
                                                        <label class="col-xs-12 col-sm-3 col-md-2 control-label">昵称大小</label>
                                                        <div class="col-sm-6">
                                                             <div class='input-group'>
                                                                 <input type="text" id="namesize" class="form-control namesize" placeholder="例如: 15"  />
                                                                 <div class='input-group-addon'>px</div>
                                                            </div>
                                                        </div>
                                                    </div>
                                             </div>
                                             <div class="form-group" id="posterbg">
                                                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">海报背景</label>
                                                    <div class="col-sm-9 col-xs-12">

                                                     {if $item['bg']}{php $thisbg=toimage($item['bg']);}{else}{php $thisbg= '../addons/'.$this->modulename.'/res/images/posterbg.jpg'}{/if}

                                                       {php echo tpl_form_field_image('bg',$thisbg)}
                                                       <span class='help-block'>海报背景大小建议尺寸为: 640 * 1008</span>
                                                    </div>
                                                </div>
                                          </div>
                                   </div>
                                    </td>
                                </tr>
                        </table>
                    </div>
                     </div>
                 <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
                    <div class="col-sm-9 col-xs-12">
                              
                             <div class="help-block" style="font-size:18px; color:#ff0000">修改海报之前先清空海报缓存：<a id="delallqr" style="cursor:pointer; font-size:30px;"><b>》》》清空海报《《《</b></a></div>
                        </div>
                </div>

                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">模版选择</label>
                    <div class="col-sm-9 col-xs-12">
                       <div class="radio">
                          <label>
                            <input type="radio" name="mbstyle" id="style1" value="style1"  {if $item['mbstyle'] =='style1' || empty($item['mbstyle'])} checked{/if} >
                            模版(默认)
                          </label>
                       </div>
                       <div class="radio" style="display:none">
                          <label>
                            <input type="radio" name="mbstyle" id="style2" value="style2"  {if empty($item['mbstyle'])} checked="checked" {/if}  {if $item['mbstyle'] =='style2'} checked{/if}>
                            模版(可以自定义颜色)
                          </label>
                       </div>
                    </div>
                </div>
                <div class="form-group" style="display:none">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">模版颜色</label>
                    <div class="col-sm-9 col-xs-12">
                        {php echo tpl_form_field_color('mbcolor',$item['mbcolor'])}
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">字体样式</label>
                    <div class="col-sm-9 col-xs-12">
                            <input type="text" class="form-control" placeholder="请填写 msyhbd.ttf 字体文件名" name="mbfont" value="{$item['mbfont']}">
                             <div class="help-block">字体文件放在 /attachment/font/ 目录，字体格式为 .ttf ,字体名称必须为字母 <a href="#" target="_blank">【请从模块售后群中下载】</a></div>
                        </div>
                </div>

                <input type="hidden" name="credit" value="0">

            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">奖励详情(填入数字)</label>
                <div class="col-sm-3 col-xs-12">
				       <div class="input-group" style="display:none">
                          <div class="input-group-addon">自然关注奖励</div>
                          <input type="number" name="fscore" value="{$item['fscore']}" class="form-control" placeholder="填写数字" aria-describedby="basic-addon2">
                          <span class="input-group-addon" id="basic-addon2">积分</span>
                       </div>
                       <div class="input-group" >
                          <div class="input-group-addon">邀请首次关注</div>
                          <input type="number" name="score" value="{$item['score']}" class="form-control" placeholder="填写数字" aria-describedby="basic-addon2">
                          <span class="input-group-addon" id="basic-addon2">积分</span>
                       </div>
                       <div class="input-group" >
                          <div class="input-group-addon">上级奖励</div>
                          <input type="number" name="cscore" value="{$item['cscore']}" class="form-control" placeholder="填写数字" aria-describedby="basic-addon2">
                          <span class="input-group-addon" id="basic-addon2">积分</span>
                       </div>
                       <div class="input-group">
                          <div class="input-group-addon">上上级奖励</div>
                          <input type="number" name="pscore" value="{$item['pscore']}" class="form-control" placeholder="填写数字" aria-describedby="basic-addon2">
                          <span class="input-group-addon" id="basic-addon2">积分</span>
						  
						  
                       </div>
					   <span class="help-block" style="display:none">三级奖励：填写0即为关闭此等级奖励</span>
                </div>
            </div>

                <input type="hidden" name="gid" value="3">
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">首次生成图片文字提示</label>
                    <div class="col-sm-9 col-xs-12">
                            <input type="text" class="form-control" placeholder="" name="addinfo1" value="{$item['addinfo1']}">
                           <span class="help-block">注意:#时间#为海报到期时间(例：你的海报将于#时间#失效，过期后请点击[生成海报]菜单生新获取哦。\n正在为您生成海报，请稍候……)</span>

                        </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">首次生成图片, 文字提示</label>
                    <div class="col-sm-9 col-xs-12">
                            <input type="text" class="form-control" placeholder="" name="addinfo2" value="{$item['addinfo2']}">
                           <span class="help-block">因为首次获取二维码需要的时间较久，在生成途中再次提示一下用户，避免用户没有耐心等待。不希望推送本条文字，可以不填写。</span>

                        </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">活动时间</label>
                    <div class="col-sm-9 col-xs-12">
                {php echo tpl_form_field_date('starttime', date('Y-m-d H:i:s',empty($item['starttime'])?time():$item['starttime']), true)}
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">结束时间</label>
                    <div class="col-sm-9 col-xs-12">
                {php echo tpl_form_field_date('endtime', date('Y-m-d H:i:s',empty($item['endtime'])?time()+3600*240:$item['endtime']), true)} 
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"> 活动未开始提示语</label>
                    <div class="col-sm-9 col-xs-12">
                            <input type="text" class="form-control" placeholder="" name="nostarttxt" value="{$item['nostarttxt']}">
                        </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"> 活动已结束提示语</label>
                    <div class="col-sm-9 col-xs-12">
                            <input type="text" class="form-control" placeholder="" name="endtxt" value="{$item['endtxt']}">
                        </div>
                </div>

                <!--div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">排行榜显示人数</label>
                    <div class="col-sm-9 col-xs-12">
                         <input type="number" min="1" class="form-control" placeholder="" name="slideH" value="{$item['slideH']}">
                    </div>
                </div-->
                
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">取消关注</label>
                    <div class="col-sm-9 col-xs-12">
                    	<div class="input-group">
                    	<div class="input-group-addon">扣除上级积分</div>
                    	 <input type="number" min="-1" class="form-control" name="rscore" value="{php echo intval($item['rscore'])}">
                    	</div>
                    	<div class="help-block">注意：0代表不扣积分；-1代表扣除他获取的积分； </div>
                    </div>
                </div>
                 <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
                    <div class="col-sm-9 col-xs-12">
                    	<div class="input-group">
                    	 <div class="input-group-addon">通知上级提示语</div>
                    	 <input type="text" class="form-control" name="rtips" value="{$item['rtips']}">
                    	</div>
                    	<div class="help-block"> #昵称#会取消关注者昵称；#积分#为扣除的积分；不填则并不通知(例：你的朋友#昵称#取消关注了，扣除您#积分#积分)</div>
                    </div>
                </div>
                
            <div class="panel-body">
            <div class="form-group" >
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
                    <div class="col-sm-9 col-xs-12">
                            <input type="submit" name="submit" value="保存海报设置" class="btn btn-primary col-lg-3"  />
                    </div>
            </div>
        	</div>
 		</div>
 </div>
  <div class="panel panel-default">
            <div class="panel-heading">
                海报邀请文字自定义
            </div>
            <div class="panel-body">
                <div class="form-group">
                    	<label class="col-xs-12 col-sm-3 col-md-2 control-label">首次关注提示语</label>
                        <div class="col-sm-9">
                        	 <input type="text" class="form-control" placeholder="" name="ftips" value="{$item['ftips']}">
                        	 <span class="help-block">提示：#积分#为粉丝获得的积分(例：恭喜您获得#积分#积分)</span>
                        </div>
                </div>
                <div class="form-group">
                    	<label class="col-xs-12 col-sm-3 col-md-2 control-label">推广上级提示语</label>
                        <div class="col-sm-9">
                        	 <input type="text" class="form-control" placeholder="" name="utips" value="{$item['utips']}">
                        	 <span class="help-block">提示：#积分#为粉丝获得的积分，#昵称#为其下级昵称(例：你的朋友#昵称#成为你的金星粉丝！恭喜您获得邀请奖励#积分#积分)</span>
                        </div>
                </div>
            	<div class="form-group">
                    	<label class="col-xs-12 col-sm-3 col-md-2 control-label">推广上上级提示语</label>
                        <div class="col-sm-9">
                        	 <input type="text" class="form-control" placeholder="" name="utips2" value="{$item['utips2']}">
                        	 <span class="help-block">提示：#积分#为粉丝获得的积分，#昵称#为其下级昵称(例：你朋友的朋友#昵称#成为你的银星粉丝！恭喜您获得邀请奖励#积分#积分)</span>
                        </div>
                </div>

                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
                    <div class="col-sm-9 col-xs-12">
                            <input type="submit" name="submit" value="保存自定义文字设置" class="btn btn-primary col-lg-3"  />
                    </div>
                </div>
            </div>
</div>


            
 <div class="panel panel-default"  style="display:none">
            <div class="panel-heading">
                扫码关注后推送内容设置：
            </div>
            <div class="panel-body">
            	<div id="news" style="display: none;">
	                <div class="form-group">
	                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">信息标题</label>
	                    <div class="col-sm-9 col-xs-12">
	                        <input type="text" id="title" name="stitle[]" class="form-control"  />
	                        <div class="help-block">注意：#昵称#为当前粉丝昵称</div>
	                    </div>
	                </div>
	                <div class="form-group">
	                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">图片链接</label>
	                    <div class="col-sm-9 col-xs-12">
	                        {php echo tpl_form_field_image('sthumb[]', '');}
	                    </div>
	                </div>
	
	                <div class="form-group">
	                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"> 简要说明</label>
	                    <div class="col-sm-9 col-xs-12">
	                        <input type="text" id="desc" name="sdesc[]" class="form-control"  />
	                    </div>
	                </div>
	
	                <div class="form-group">
	                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">跳转链接</label>
	                    <div class="col-sm-9 col-xs-12">
	                       {php echo tpl_form_field_link('surl[]','')}
	                    </div>
	                </div>
	            </div>
                {loop $slist $l}
                <div class="news">
	                <div class="form-group">
	                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">标题</label>
	                    <div class="col-sm-9 col-xs-12">
	                        <input type="text" id="title" name="stitle[]" class="form-control" value="{$l['stitle']}"  />
	                        <div class="help-block">注意：#昵称#为当前粉丝昵称</div>
	                    </div>
	                </div>
	                <div class="form-group">
	                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">图片链接</label>
	                    <div class="col-sm-9 col-xs-12">
	                        {php echo tpl_form_field_image('sthumb[]', $l['sthumb']);}
	                    </div>
	                </div>
	
	                <div class="form-group">
	                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"> 说明</label>
	                    <div class="col-sm-9 col-xs-12">
	                        <input type="text" id="desc" name="sdesc[]" class="form-control" value="{$l['sdesc']}"  />
	                    </div>
	                </div>
	
	                <div class="form-group">
	                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">跳转链接</label>
	                    <div class="col-sm-9 col-xs-12">
	                       {php echo tpl_form_field_link('surl[]',$l['surl'])}
	                    </div>
	                </div>
                </div>
                {/loop}
                <div class="form-group">
                    	<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
                        <div class="col-sm-9">
                        	<a onclick="onAdd2(this)" class="btn btn-warning"><i class="fa fa-plus"></i> 添加图文</a>
	                         <span class="help-block">图文数量大于1时，推送多图文，否则单图文；标题为空即为删除</span>
                        </div>
                </div>
            </div>
				</div>

<input type="hidden" name="data" value="" />
</div>
<script src="../addons/{php echo $this->modulename}/res/js/poster.js" type="text/javascript"></script>
<script>

$('#delallqr').click(function(){
     	$.ajax({
     		url:"{php echo $this->createWebUrl('delallqr',array('pid'=>$item['id']))}",
     		type:'post',
     		success:function(msg){
     			if (msg==1){
				alert('清理成功！');
				}else{
				
				alert('清理失败！');
				}
				
     		}
     	});
     });


function onAdd2(obj){
	$(obj).parent().parent().before('<div class="news">'+$('#news').html()+'</div>');
}

var gqrt = 0;
var attachurl = "{$_W['attachurl']}";
var ncounter = 0;
    
         function nb_bind(obj){
            var imgsset = $('#imgsset');
            var namesset = $("#namesset");
             imgsset.hide();
             namesset.hide();
             deleteTimers();
             var type = obj.attr('type');
             if(type=='name'){
                  namesset.show();
                  var size = obj.attr('size') || "16";
                  var picker = namesset.find('.sp-preview-inner');
                  var input = namesset.find('input:first');
                  var namesize = namesset.find('#namesize');
                  var color = obj.attr('color') || "#000";
                  input.val(color); namesize.val(size.replace("px",""));  
                  picker.css( {'background-color':color,'font-size':size});
                  ncounter = setInterval(function(){
                       obj.attr('color',input.val()).find('.text').css('color',input.val());
                       obj.attr('size',namesize.val() +"px").find('.text').css('font-size',namesize.val() +"px");
                   },100);
             }  
         }
         var bscounter = 0 ;        
    $(function(){
        {if !empty($item['id'])}
          $('.drag').each(function(){
              dragEvent($(this));
          })
        {/if}
          
        	  $('.btn-poster').click(function(){
                  var imgsset = $('#imgsset');
                  var namesset = $("#namesset");
                  imgsset.hide();
                  namesset.hide();
                  deleteTimers();
                   var type = $(this).data('type');
                   var img = "";
                 	if(type=='img' || type=='thumb'){
                       img = '<img src="../addons/{php echo $this->modulename}/res/images/default.jpg" />';
                   }else if(type=='name'){
                       img = '<div class=text>昵称</div>';
                   }else if(type=='qr'){
                       img = '<img src="../addons/{php echo $this->modulename}/res/images/qr.png" />';
                   }
                   var index = $('#nb_poster .drag').length+1;
                   var obj = $('<div class="drag" type="' + type +'" index="' + index +'" style="z-index:' + index+'">' + img+'<div class="dRightDown"> </div><div class="dLeftDown"> </div><div class="dRightUp"> </div><div class="dLeftUp"> </div><div class="dRight"> </div><div class="dLeft"> </div><div class="rUp"> </div><div class="rDown"></div></div>');
                   $('#nb_poster').append(obj);
                   dragEvent(obj);
               });
           
                $('.drag').click(function(){
                    nb_bind($(this));
                })
            
    })
 var imgcounter = 0 ;   
     $(':submit').click(function(){
    	 if($.trim($('#title').val()) == ''){
            alert('请输入海报名称!');
            return false;
        }
        var poster = [];
        $('.drag').each(function(){
            var obj = $(this);
            var type = obj.attr('type');
            var left = obj.css('left');
            var top = obj.css('top');
            var d= {left:left,top:top,type:obj.attr('type'),width:obj.css('width'),height:obj.css('height')};
            if(type=='name'){
                d.size = obj.attr('size');
                d.color = obj.attr('color');
            }
            poster.push(d);
        });
        $('input[name="data"]').val(JSON.stringify(poster));
        return true;
    });
    </script>
